const state = {
  sidebarOpened: false, // 侧边状态
  iframeUrl: '',
  addRouters: [], // 动态路由
  leftMenuSelected: [], // 左边菜单选中
  leftMenuParent: [] // 左边菜单选中父菜单
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    state.sidebarOpened = !state.sidebarOpened
  },
  SET_IFRAME_URL: (state, url) => {
    state.iframe.url = url
  },
  SET_ROUTERS: (state, routers) => {
    state.addRouters = routers
  },
  SET_LEAF_MENU_SELECTED: (state, key) => {
    state.leftMenuSelected = []
    state.leftMenuSelected.push(key)
  },
  SET_LEAF_MENU_PARENT: (state, key) => {
    state.leftMenuParent.push(key)
    console.log(state.leftMenuParent)
  }
}

const actions = {
  toggleSideBar ({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  setIframeUrl ({ commit }, url) {
    commit('SET_IFRAME_URL', url)
  },
  setRouters ({ commit }, addRouters) {
    commit('SET_ROUTERS', addRouters)
  },
  setCurrentMenu ({ commit }, currentMenu) {
    commit('SET_LEAF_MENU_SELECTED', currentMenu.selectKey || '')
    commit('SET_LEAF_MENU_PARENT', currentMenu.parentMenuKey || '')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
